package com.zho.common.consumer.email;

import java.util.List;

import com.zho.common.consumer.DefaultOutDataService;

import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessagePreparator;

public class EmailOutDataService extends
		DefaultOutDataService<MimeMessagePreparator> {
	private JavaMailSender mailSender;

	/**
	 * @param mailSender
	 *            the mailSender to set
	 */
	public void setMailSender(JavaMailSender mailSender) {
		this.mailSender = mailSender;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see vn.com.vistar.commons.consumer.IOutDataService#checkAvailable()
	 */
	public boolean checkAvailable() {
		return true;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see vn.com.vistar.commons.consumer.IOutDataService#send(java.util.List)
	 */
	public boolean send(List<MimeMessagePreparator> data) throws Exception {
		if (data != null) {
			for (MimeMessagePreparator msg : data) {
				mailSender.send(msg);
			}
		}
		return true;
	}

}
